package org.vectrics.common.util;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.PatternLayout;
import org.vectrics.SystemException;


public class LoggingInitialize {
 
	
	/*
	 * Initialize logging, if not already started.
	 */
	public static void initialize(String fileName) {
		BasicConfigurator.resetConfiguration();
		BasicConfigurator.configure();
		try {
			FileAppender fileAppender = new FileAppender(
					new PatternLayout("%-6r [%15.15t] %-5p %30.30c %x - %m\r\n"), fileName);
			fileAppender.setName("FILE_APPENDER");
			fileAppender.setAppend(true);
			fileAppender.setThreshold(Level.DEBUG);
			LogManager.getRootLogger().addAppender(fileAppender);
		}
		catch (Exception ex) {
			throw new SystemException("main() - exception creating file appender", ex);
		}
	    
		LogManager.getRootLogger().setLevel(Level.INFO);
	}
	
}
